<template>
	<view :class="['exchange',device == 'ios'?'iosPadding':'androidPadding']">
		<view :class="device=='ios'?'ios_pageTitle':'and_pageTitle'">
			<view class="statusBar"></view>
			<view :class="['pageTitle','dFlex','jBetween_aCenter']">
				<view class="backIcon imgPublic" @tap='tool.back()'>
					<image src="../static/images/back.png" mode="widthFix"></image>
				</view>
				<view class="title">转赠洗护券</view>
				<view class="backIcon imgPublic"></view>
			</view>
		</view>
		<view class="container">
			<view class="bgColor dFlex flexDirection jCenter_aCenter">
				<text>洗护券</text>
				<view class="showCount">{{userInfo.gold}}</view>
			</view>
			<view class="tixian">
				<view class="part1">
					<view class="tit">赠送金额</view>
					<view class="partIpt dFlex jStart_aCenter">
						<!-- <view class="iptTit"></view> -->
						<view class="ipt">
							<input type="number" v-model="amount" :max='userInfo.gold' placeholder="请输入赠送金额">
						</view>
					</view>
				</view>
				<view class="part1">
					<view class="tit">赠送账户</view>
					<view class="partIpt dFlex jStart_aCenter">
						<!-- <view class="iptTit"></view> -->
						<view class="ipt">
							<input type="number" v-model="memberIds" placeholder="请输入对方邀请码">
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class='btns' @tap='subInfo'>赠送</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				identity:uni.getStorageSync('identify')?uni.getStorageSync('identify'):'1',
				device: getApp().globalData.platform,
				userInfo:{},
				amount:'',
				memberIds:'',
			};
		},
		onShow(){
			if(this.identity == '1'){
				this.initUser();
			}else{
				this.initStaff();
			}
		},
		onShareAppMessage() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		onShareTimeline() {
			return{
				title:'洗匣士~您的家居窗帘清洗助手',
				path:'/pages/home?spreadId=' + (uni.getStorageSync('userId')?uni.getStorageSync('userId'):''),
				imageUrl:getApp().globalData.imgDomain+'public/logo.png',
				desc:'手机下单 | 专员取送 | 生态环保 | 轻奢洗护',
			}
		},
		methods:{
			initUser(){
				this.tool.getUserInfo().then(res=>{
					if(res){
						this.userInfo = res;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			initStaff(){
				this.tool.getStaffInfo().then(res=>{
					console.log(res);
					if(res){
						this.userInfo = res;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 提交提现信息
			subInfo(){
				if(!this.amount){
					uni.showToast({
						title:'请输入赠送金额',
						icon:'none'
					})
					return
				}
				if(!this.memberIds){
					uni.showToast({
						title:'请输入对方邀请码',
						icon:'none'
					})
					return
				}
				uni.showModal({
					content:'确定填写无误',
					success: (op) => {
						if(op.confirm){
							this.tool.getData('User/doChange',{
								memberId:uni.getStorageSync('userId')?uni.getStorageSync('userId'):'',
								amount:this.amount,
								memberIds:this.memberIds,
								type:6
							}).then(res=>{
								console.log(res);
								if(res){
									uni.showToast({
										title:'赠送成功',
										icon:"success"
									})
									this.initUser();
									this.amount = '';
									this.memberIds = '';
								}
							}).catch(err=>{
								console.log(err);
							})
						}
					},
					fail:(err)=>{
						
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		// background: white;
	}
	.exchange{
		width: 100%;
		.btns{
			width: 100%;
			position: fixed;
			left:0;
			bottom: 0;
			color: white;
			background: linear-gradient(#609ff8 0%, #1664ff 100%);
			border-radius: 5px;
			padding: 12px 0;
			text-align: center;
		}
		.container{
			width: 100%;
			.tixian{
				width: 100%;
				padding: 20px 4%;
				box-sizing: border-box;
				.part1{
					width: 100%;
					margin-bottom: 20px;
					.toast{
						color: #999999;
						margin-top: 12px;
					}
					.partIpt{
						width: 100%;
						background: #ffffff;
						border-radius: 5px;
						box-shadow: 3.29px 6.74px 10px 0px rgba(87,85,217,0.10); 
						padding: 16px;
						box-sizing: border-box;
						margin-bottom: 12px;
						.iptTit{
							width: 20%;
						}
						.ipt{
							flex: 1;
						}
					}
					.partIpt:last-child{
						margin: 0;
					}
					.tit{
						width: 100%;
						font-size: 16px;
						font-weight: bold;
						margin-bottom: 12px;
						.other{
							color: #1664FF;
							font-size: 14px;
							font-weight: 400;
						}
					}
				}
			}
			.bgColor{
				width: 100%;
				background: linear-gradient(0deg,#609ff8 0%, #0e64ff 100%);
				// height: calc(195px - var(--status-bar-height) - 57px);
				padding: 16px 0 20px;
				color: white;
				font-size: 16px;
				.showCount{
					font-size: 36px;
					font-weight: bold;
					margin-top: 6px;
				}
			}
		}
	}
	.ios_pageTitle,
	.and_pageTitle {
		background: #0e64ff;
		color: white;
	}
</style>
